package com.coffee.takeoutserver.controller;

import com.coffee.takeoutserver.bean.GoodsTypeInfo;
import com.coffee.takeoutserver.bean.MyCollection;
import com.coffee.takeoutserver.bean.Seller;
import com.coffee.takeoutserver.service.CollectionService;
import com.coffee.takeoutserver.service.GoodsTypeInfoService;
import com.coffee.takeoutserver.service.SellerService;
import com.coffee.takeoutserver.util.RequestType;
import com.coffee.takeoutserver.util.ResponseInfo;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class GoodsTypeInfoController {

    @Autowired
    GoodsTypeInfoService goodsTypeInfoService;

    @RequestMapping("getGoodsTypeInfoListBySellerId")
    @ResponseBody
    public String getGoodsTypeInfoListBySellerId(int sellerId) {
        Gson gson = new Gson();
        List<GoodsTypeInfo> goodsTypeInfoList = goodsTypeInfoService.getGoodsTypeInfoListBySellerId(sellerId);
        Map<String,String> map = new HashMap<>();
        map.put("requestType",RequestType.GetGoodsTypeInfoListBySellerId );
        map.put("goodsTypeInfoList",gson.toJson(goodsTypeInfoList));
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode("0");
        responseInfo.setData(gson.toJson(map));;
        return gson.toJson(responseInfo);
    }

    @RequestMapping("deleteGoodsTypeInfoById")
    @ResponseBody
    public String deleteGoodsTypeInfoById(int id) {
        Gson gson = new Gson();
        goodsTypeInfoService.deleteGoodsTypeInfoById(id);
        Map<String,String> map = new HashMap<>();
        map.put("requestType",RequestType.DeleteGoodsTypeInfoById );
        map.put("info","success");
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode("0");
        responseInfo.setData(gson.toJson(map));;
        return gson.toJson(responseInfo);
    }

    @RequestMapping("insertGoodsTypeInfo")
    @ResponseBody
    public String insertGoodsTypeInfo(@RequestBody GoodsTypeInfo goodsTypeInfo) {
        Gson gson = new Gson();
        goodsTypeInfoService.insertGoodsTypeInfo(goodsTypeInfo);
        Map<String,String> map = new HashMap<>();
        map.put("requestType",RequestType.InsertGoodsTypeInfo );
        map.put("goodsTypeInfo",gson.toJson(goodsTypeInfo));
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode("0");
        responseInfo.setData(gson.toJson(map));;
        return gson.toJson(responseInfo);
    }

    @RequestMapping("updateGoodsTypeInfoById")
    @ResponseBody
    public String updateGoodsTypeInfoById(@RequestBody GoodsTypeInfo goodsTypeInfo) {
        Gson gson = new Gson();
        goodsTypeInfoService.updateGoodsTypeInfoById(goodsTypeInfo);
        Map<String,String> map = new HashMap<>();
        map.put("requestType",RequestType.UpdateGoodsTypeInfoById );
        map.put("goodsTypeInfo",gson.toJson(goodsTypeInfo));
        ResponseInfo responseInfo = new ResponseInfo();
        responseInfo.setCode("0");
        responseInfo.setData(gson.toJson(map));;
        return gson.toJson(responseInfo);
    }
}
